package com.lun.medium;

import java.util.LinkedList;
import java.util.List;

public class PathInZigzagLabelledBinaryTree {
    public List<Integer> pathInZigZagTree(int label) {
    	List<Integer> result = new LinkedList<>();
    	while(label > 0) {
    		result.add(0, label);
    		if(label == 1) break;
    		int min = 1;
    		for(int i = 1; (label >>> i) > 0; i++)
    			min <<= 1;
    		label = ((min + (min << 1) - 1) >> 1) - (label >> 1);
    	}
    	return result;
    }
}
